package com.example.wan_android.ui.activity

import android.util.Log
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.wan_android.BR
import com.example.wan_android.R
import com.example.wan_android.adapter.CollectionAdater
import com.example.wan_android.databinding.ActivityCollectionBinding
import com.example.wan_android.tools.SpacesItemDecoration
import com.example.wan_android.viewmodel.CollectionViewModel

class CollectionActivity : BaseActivity<ActivityCollectionBinding, CollectionViewModel>(
    CollectionViewModel::class.java,
    R.layout.activity_collection,
    BR.viewModel
) {
    private val adapter by lazy {
        CollectionAdater(mViewModel!!)
    }

    override fun initView() {
        mViewModel?.collectionLiveData?.observe(this) {
            it.onSuccess { data ->
                adapter.setListData(data)
            }
            it.onFailure { data ->
                Log.i("TAG", "initView: $data")
            }
        }
        mViewDataBinding?.rvCollectionList?.adapter = adapter
        mViewDataBinding?.rvCollectionList?.addItemDecoration(SpacesItemDecoration(30))
        mViewDataBinding?.rvCollectionList?.layoutManager = LinearLayoutManager(this)
    }

}